#----------------------------
# Name: Chris Spooner
# Project: Madlibs.py
# Period: 2
# Start Date: 9/17/2013
# Last Revision Date: 9/17/2013
# Version: 1.0.0
#----------------------------
anthe = " and lived happily ever after with a"
bstweopen = " You look around and pick up"   
blank = "________"
nwlfe = " to start your new life"
swearFilter = ["dumb",
               "stupid",
               "retard",
               "ass",
               "shit",
               "fuck",
               "cock",
               "dick",
               "cunt",
               "fucked",
               "sucked",
               "raped",
               "butt fuck",
               "rape",
               "raped",
               "nigger"]
               
              
              
def displayStartScreen():
    print "Madlibs"
    raw_input("Press Enter to Continue")
    
def displayEndScreen():
    print "Goodbye"
    raw_input("Press Enter to Exit")

def getMenuOption(maxOption):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter Number or Q> ")
        option = option.upper()
        for num in range(1, maxOption+2):
            if option == str(num):
                goodOption = True
        if option == 'Q':
            goodOption = True
        if not goodOption:
            print "Please pick a valid option!"
    return option
        
def menu(options):
    print "------Please Select a Story------"
    print " [1] The End of the Day"
    print " [2] My New Pet"
    print " [3] Rammstein, Liebe ist fur alle Da"
    print " [Q] Quit"
    print "----------------------------------"
    option = getMenuOption(options)
    return option

    
def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearFilter:
            goodWord = True
        else:
            print "Naughty player...please be polite."
        if not goodWord:
            print "Try again"
    return word
    
def getNumber(prompt, max = "", min = ""):
    num = ""
    goodNum = False
    while not goodNum:
        isNum = True
        num = raw_input(prompt)
        for character in num:
            if character not in "0123456789":
                isNum = False
        if min != "":
            if isNum:
                if float(num) < min:
                    isNum = False
        if max != "":
            if isNum:
                if float(num) > max:
                    isNum = False
        if isNum:
            goodNum = True
        else:
            print "Not a valid number, try again."
    return num

def formatstring(string, width=80, buff=10):
    newString=""
    count = 0
    for character in string:
        count +=1
        if character == " ":
            if count >= width - buff:
                newString += "\n"
                count = 0
            else:
                newString += character
        else:
            newString += character
    return newString

def story1():
    place1 = getWord("Enter a place: ")
    story = "It was near the end of the day at"
    story += " " + place1 + ", when "
    print formatstring(story)
    print
    
    name1 = getWord("Enter a name: ")
    story += "" + name1 + " " + "found a "
    print formatstring(story)
    print
   
    noun1 = getWord("Enter a noun: ")
    story += "" + noun1 + " under a tree. "
    print formatstring(story)
    print
    
    
    
    verb2 = getWord("Enter a verb, past tense: ")
    story += " " + name1.capitalize() 
    story += " " + verb2 + "" 
    print formatstring(story), blank, anthe
    

    noun2 = getWord("Fill in the blank: ")
    story += " " + noun2 + " and lived happily ever after with a" 
    print formatstring(story)
    print
    
    
   
    story += " " + noun1 + ". The end :) "
    print formatstring(story)
    print
    
def story2():
    
    animal = getWord("Enter a animal: ")
    story = "Today I went to adopt a"
    story += " " + animal + ", named "
    print formatstring(story)
    print
    
    name1 = getWord("Enter a name: ")
    story += "" + name1 + "." 
    print formatstring(story)
    print
   
    place = getWord("Enter a place: ")
    story += " " + name1.capitalize() + " and I went to " + place + " and lived in an apartment together. "
    print formatstring(story)
    print
    
  
    story += "" + "Until one day when " + name1.capitalize() + ", morphed into a super mega giant beast."
    print formatstring(story+bstweopen)
    print
    
    noun3 = getWord("Enter a noun: ")
    story += "" + " You look around and pick up a " + noun3 + "."
    print formatstring(story)
    print
    
    nstory = ""
    
    noun4 = getWord("Enter a noun: ")
    nstory += "" + " You start attacking the beast when all of the sudden a " + noun4 + " shot out of the monsters head."
    print formatstring(nstory)
    print
    
   
    
    nstory += "" + " The " + noun4 + "s" + " begin exploding all around you." + " Thinking fast you throw the " + noun3 + " at the monster." + " It screeches out and falls to the ground, blood spraying everywhere. You go in for the finishing move and use " 
    print formatstring(nstory)
    print
    
    noun5 = getWord("Enter a noun: ")
    nstory += "" + noun5
    print formatstring(nstory)
    print
    
    place2 = getWord("enter a noun:")
    nstory += " You defeat the beast and move to, " + place2
    print formatstring(nstory+nwlfe)
    print
    
def story3():
    place1 = getWord("Enter a place: ")
    story = "Today Rammstein came to" 
    story += " " + place1 + ", a friend named "
    print formatstring(story)
    print
    
    
    name1 = getWord("Enter a friend's name: ")
    story += name1 + " and I travelled to the concert by "
    print formatstring(story)
    print
    
    vehicle = getWord("Enter a vehicle name: ")
    story += "" + vehicle + "."
    print formatstring(story)
    print
    
    
    num1 = getWord("Enter a number: ")
    story +=  " After travelling for " + num1 + " days, we decided to get some food."
    print formatstring(story)
    print
    
    food1 = getWord("Enter a food: ")
    story += "So we grabbed a " + food1 + "."
    print formatstring(story)
    print

    story += " " + name1.capitalize() + " and I rushed to the concert. We got in just in time. It was AAWWWSSSOOMMMEEE. The lights were cool, there was fog, and pyro-technics, and a bunch of awesome stuff."
    print formatstring(story)
    print
    
    
    noun1 = getWord("Enter a noun: ")
    story += " After the concert we were so tired, that we fell asleep on a " + noun1 + "."
    print formatstring(story)
    print
    
    place2 = getWord("Enter a place: ")
    story += " Then we made the journey home, are musical needs fulfilled. We parted ways, I went back to my home in " + place2 + ". The End :)" 
    print formatstring(story)
    print
    
    
    
    
    
    
    
    
    
def run():
    displayStartScreen()
    choice = ""
    while choice != 'Q':
        choice = menu(2)
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
            
        elif choice == 'Q':
            displayEndScreen()
        else:
            print "Something Awful Ocurred...yell at programmer!"
    exit()
run()